package org.linlinjava.litemall.db.service;

import org.apache.ibatis.annotations.Param;
import org.linlinjava.litemall.db.dao.LitemallNewsMapper;
import org.linlinjava.litemall.db.dao.LitemallTiXianMapper;
import org.linlinjava.litemall.db.domain.LitemallNews;
import org.linlinjava.litemall.db.domain.LitemallTiXian;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class LitemallTiXianService  {

    @Autowired
    @Resource
   private LitemallTiXianMapper litemallTiXianMapper;



    public Map<String,Object> adminselectallwtx(String username, Integer tixianjin, String shenpitime, String endTime, Integer page, Integer limit, String sort, String order) {

        Map<String,Object> tixianMap=new HashMap<>();
        int currPage= (page-1)*limit;
        tixianMap.put("list",litemallTiXianMapper.adminselectallwtx(username,tixianjin,shenpitime,endTime,currPage, limit, sort, order));
        Integer total = litemallTiXianMapper.total(username, tixianjin, shenpitime, endTime);
        //59  / 20  == 2.xx  % 10 !=0
        int pages= (total+limit-1)/limit;
        tixianMap.put("pages",pages);
        tixianMap.put("total",total);
        tixianMap.put("limit",limit);
        tixianMap.put("page",page);
        return tixianMap;
    }




    public List<LitemallTiXian> adminselectallytx() {
        return litemallTiXianMapper.adminselectallytx();
    }


    public LitemallTiXian findbyid(int id) {
        return litemallTiXianMapper.findbyid(id);
    }


    public List<LitemallTiXian> userselectall(int userid,int  page) {
        int size= 20;

            page=(page-1)*size;


        return litemallTiXianMapper.userselectall( userid,page,size);
    }


    public int inserttx(LitemallTiXian litemallTiXian) {
        return litemallTiXianMapper.inserttx(litemallTiXian);
    }


    public int updatetx(LitemallTiXian litemallTiXian) {
        return litemallTiXianMapper.updatetx(litemallTiXian);
    }

    public     String  myresult(int  userid) {
        return litemallTiXianMapper.myresult(userid);
    }
}
